//
//  XJkaochaViewController.m
//  gangquOASystem
//
//  Created by michael on 2018/7/25.
//  Copyright © 2018年 czd. All rights reserved.
//

#import "XJkaochaViewController.h"

@interface XJkaochaViewController ()

@end

@implementation XJkaochaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"外出参观学习考察活动审批表";
        self.view.backgroundColor = [UIColor whiteColor];
//19
    // Do any additional setup after loading the view.
    [self initview];
}
- (void)initview{
if(!_tableView){
 _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth,KScreenHeight-kTopHeight) style:UITableViewStylePlain];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.bounces = NO;
_tableView.dataSource = self;
_tableView.delegate = self;
    self.tableView.backgroundColor = [UIColor whiteColor];

[self.view addSubview:_tableView];

}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 14;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row ==3) {
    return 140;
}else if (indexPath.row ==6) {
    return 20;
}else if (indexPath.row ==7||indexPath.row ==8||indexPath.row ==9||indexPath.row ==10) {
    return 200;
}
else{
    return 60;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

if(indexPath.row ==0){

static NSString *cellid00 = @"cellid00";
    newTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid00];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[newTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid00];
    }
    cell.seltag = 100+indexPath.row;
    cell.string = @"组织单位(盖章)";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}else if (indexPath.row ==1){

static NSString *cellid01 = @"cellid01";
    newTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid01];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[newTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid01];
    }
    cell.seltag = 100+indexPath.row;
    cell.string = @"带队领导";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}else if (indexPath.row ==2){
 static NSString *cellid02 = @"cellid02";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid02];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid02];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.text = @"外出时间";
//label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
   
     _starttimebutton = [zhucebutton buttonWithType:UIButtonTypeCustom];
      _starttimebutton.frame = CGRectMake(10, label.bottom, (KScreenWidth-20-50)/2, 40);
[_starttimebutton addTarget:self action:@selector(startaction) forControlEvents:UIControlEventTouchUpInside];
   [cell.contentView addSubview:_starttimebutton];
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(_starttimebutton.right, label.bottom,50, 40)];
  label2.textColor = [UIColor colorWithHexString:@"484848"];
label2.text = @"到";
label2.textAlignment = 1;
    label2.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label2];
     _endtimebutton = [zhucebutton buttonWithType:UIButtonTypeCustom];
      _endtimebutton.frame = CGRectMake(label2.right, label.bottom, (KScreenWidth-20-50)/2, 40);
[_endtimebutton addTarget:self action:@selector(endaction) forControlEvents:UIControlEventTouchUpInside];
   [cell.contentView addSubview:_endtimebutton];
    [_starttimebutton setTitle:@"开始时间" forState:UIControlStateNormal];
         [_endtimebutton setTitle:@"结束时间" forState:UIControlStateNormal];

}
  if(_starttime.length>0){
         [_starttimebutton setTitle:_starttime forState:UIControlStateNormal];
         }
           if(_endtime.length>0){
         [_endtimebutton setTitle:_endtime forState:UIControlStateNormal];
}
    

return cell;
}
else if (indexPath.row ==3){
 static NSString *cellid03 = @"cellid03";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid03];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid03];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.text = @"外出人员名单";
//label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _persontextview = [[zhucetextview alloc]init];
              _persontextview.delegate = self;
    _persontextview.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 120);
 
          [cell.contentView addSubview:_persontextview];

}
  
return cell;
}else if(indexPath.row ==4){

static NSString *cellid04 = @"cellid04";
    newTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid04];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[newTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid04];
    }
    cell.seltag = 100+indexPath.row;
    cell.string = @"外出事由";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}
else if(indexPath.row ==5){

static NSString *cellid05 = @"cellid05";
    newTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid05];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[newTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid05];
    }
    cell.seltag = 100+indexPath.row;
    cell.string = @"目的地";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}else if(indexPath.row ==6){

static NSString *cellid06 = @"cellid06";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid06];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid06];
         UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"0e75de"];
label.text = @"日程安排";
//label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:16];
    [cell.contentView addSubview:label];
    }
 
        return cell;

}else if(indexPath.row ==7){

static NSString *cellid07 = @"cellid07";
    kaochaTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid07];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[kaochaTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid07];
    

    }
        cell.seltag = indexPath.row;

 [cell.timebutton addTarget:self action:@selector(timeaction:) forControlEvents:UIControlEventTouchUpInside];

        return cell;

}else if(indexPath.row ==8){

static NSString *cellid08 = @"cellid08";
    kaochaTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid08];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[kaochaTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid08];
    

    }
        cell.seltag = indexPath.row;

 [cell.timebutton addTarget:self action:@selector(timeaction:) forControlEvents:UIControlEventTouchUpInside];

        return cell;

}else if(indexPath.row ==9){

static NSString *cellid09 = @"cellid09";
    kaochaTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid09];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[kaochaTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid09];
    

    }
        cell.seltag = indexPath.row;

 [cell.timebutton addTarget:self action:@selector(timeaction:) forControlEvents:UIControlEventTouchUpInside];

        return cell;

}else if(indexPath.row ==10){

static NSString *cellid10 = @"cellid10";
    kaochaTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid10];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[kaochaTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid10];
    

    }
        cell.seltag = indexPath.row;

 [cell.timebutton addTarget:self action:@selector(timeaction:) forControlEvents:UIControlEventTouchUpInside];

        return cell;

}else if(indexPath.row ==11){

static NSString *cellid11 = @"cellid11";
    newTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid11];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[newTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid11];
    

    }
        cell.seltag = 100+indexPath.row;
cell.string = @"交通工具";
        return cell;

}else if(indexPath.row ==12){

static NSString *cellid12 = @"cellid12";
    newTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid12];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[newTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid12];
    

    }
        cell.seltag = 100+indexPath.row;
cell.string = @"人均所需经费(经费列支渠道)";
        return cell;

}
else{
     static NSString *CellIdentifier2 = @"Cellbendititlepic2";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

//        cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
    }
     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
      button.frame = CGRectMake(20, 10, (KScreenWidth-60)/2, 40);
button.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

    [button setTitle:@"保存" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [button setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
        button.layer.cornerRadius = button.height/2;
        [button addTarget:self action:@selector(baocunaction) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button];

     UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
      button2.frame = CGRectMake(button.right+ 20, 10, (KScreenWidth-60)/2, 40);
button2.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

    [button2 setTitle:@"发送" forState:UIControlStateNormal];
    button2.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [button2 setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
        button2.layer.cornerRadius = button.height/2;
        [button2 addTarget:self action:@selector(fasongaction) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button2];
    return cell;
    
  
    }
}
- (void)startaction{
        [self.view endEditing:YES];

_setupPicker = [[MHDatePicker alloc] init];
    _setupPicker.isBeforeTime = YES;
    _setupPicker.datePickerMode = UIDatePickerModeDate;
    
    __weak typeof(self) weakSelf = self;
    [_setupPicker didFinishSelectedDate:^(NSDate *selectedDate) {
//        NSString *string = [NSString stringWithFormat:@"%@",[NSDate dateWithTimeInterval:3600*8 sinceDate:selectedDate]];
//        weakSelf.myLabel2.text = string;
      NSString *string = [weakSelf dateStringWithDate:selectedDate DateFormat:@"yyyy-MM-dd"];
      _starttime = string;
      [weakSelf.starttimebutton setTitle:string forState:UIControlStateNormal];
    }];

}
- (void)endaction{
        [self.view endEditing:YES];

_setupPicker2 = [[MHDatePicker alloc] init];
    _setupPicker2.isBeforeTime = YES;
    _setupPicker2.datePickerMode = UIDatePickerModeDate;
    
    __weak typeof(self) weakSelf = self;
    [_setupPicker2 didFinishSelectedDate:^(NSDate *selectedDate) {
//        NSString *string = [NSString stringWithFormat:@"%@",[NSDate dateWithTimeInterval:3600*8 sinceDate:selectedDate]];
//        weakSelf.myLabel2.text = string;
      NSString *string = [weakSelf dateStringWithDate:selectedDate DateFormat:@"yyyy-MM-dd"];
      _endtime = string;
      [weakSelf.endtimebutton setTitle:string forState:UIControlStateNormal];
    }];

}
- (void)timeaction:(UIButton *)btn{
        [self.view endEditing:YES];

_timePicker = [[MHDatePicker alloc] init];
    _timePicker.isBeforeTime = YES;
    _timePicker.datePickerMode = UIDatePickerModeDate;
    zhucebutton *button = (zhucebutton *)[self.view viewWithTag:btn.tag];
    __weak typeof(self) weakSelf = self;
    [_timePicker didFinishSelectedDate:^(NSDate *selectedDate) {
//        NSString *string = [NSString stringWithFormat:@"%@",[NSDate dateWithTimeInterval:3600*8 sinceDate:selectedDate]];
//        weakSelf.myLabel2.text = string;
      NSString *string = [weakSelf dateStringWithDate:selectedDate DateFormat:@"yyyy-MM-dd"];
            [button setTitle:string forState:UIControlStateNormal];

      if (btn.tag ==7) {
       weakSelf.time1 = string;
      }
       if (btn.tag ==8) {
       weakSelf.time2 = string;
      }
       if (btn.tag ==9) {
       weakSelf.time3 = string;
      }
       if (btn.tag ==10) {
       weakSelf.time4 = string;
      }
    }];
}
      
      
   


- (NSString *)dateStringWithDate:(NSDate *)date DateFormat:(NSString *)dateFormat
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:dateFormat];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
    NSString *str = [dateFormatter stringFromDate:date];
    return str ? str : @"";
}
- (void)baocunaction{
zhucetextfield *zuzhiview = (zhucetextfield *)[self.view viewWithTag:100];//组织单位(盖章)
zhucetextfield *leaderview = (zhucetextfield *)[self.view viewWithTag:101];//带队领导
_starttime,_endtime;//
zhucetextfield *personview = (zhucetextfield *)[self.view viewWithTag:103];//外出人员名单
zhucetextfield *reasonview = (zhucetextfield *)[self.view viewWithTag:104];//外出事由
zhucetextfield *placeview = (zhucetextfield *)[self.view viewWithTag:105];//目的地
// 7 8 9 10
_time1;//时间
zhucetextfield *startview1 = (zhucetextfield *)[self.view viewWithTag:207];//启程地
zhucetextfield *endview1 = (zhucetextfield *)[self.view viewWithTag:307];//到达地

_time2;//时间
zhucetextfield *startview2 = (zhucetextfield *)[self.view viewWithTag:208];//启程地
zhucetextfield *endview2 = (zhucetextfield *)[self.view viewWithTag:308];//到达地

_time3;//时间
zhucetextfield *startview3 = (zhucetextfield *)[self.view viewWithTag:209];//启程地
zhucetextfield *endview3 = (zhucetextfield *)[self.view viewWithTag:309];//到达地

_time4;//时间
zhucetextfield *startview4 = (zhucetextfield *)[self.view viewWithTag:210];//启程地
zhucetextfield *endview4 = (zhucetextfield *)[self.view viewWithTag:310];//到达地

zhucetextfield *jiaotongview = (zhucetextfield *)[self.view viewWithTag:111];//交通工具
zhucetextfield *jingfeiview = (zhucetextfield *)[self.view viewWithTag:112];//人均经费渠道


NSString *json =[NSString stringWithFormat: @"{'organizational':'%@','leader':'%@','starttime':'%@', 'endtime':'%@','namelist':'%@','reason':'%@','destination':'%@','time1':'%@','startplace1':'%@','endplace1':'%@','time2':'%@','startplace2':'%@','endplace2':'%@','time3':'%@','startplace3':'%@','endplace3':'%@','time4':'%@','startplace4':'%@','endplace4':'%@','vehicle':'%@','channel':'%@'}",zuzhiview.text,leaderview.text,_starttime,_endtime,_persontextview.text,reasonview.text,placeview.text,_time1,startview1.text,endview1.text,_time2,startview2.text,endview2.text,_time3,startview3.text,endview3.text,_time4,startview4.text,endview4.text,jiaotongview.text,jingfeiview.text];




}
- (void)fasongaction{


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
